/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package moteur.carte;
import Interface.util;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;
import moteur.Terrain;
import moteur.Transport;

/**
 *
 * @author nlupins
 */
public class Riviere extends Arc{

    /**
     * 
     */
    public Riviere() {
        super(Terrain.AQUEU);
    }

    /**
     *
     * @return
     */
    @Override
    public Transport getPionTransport() {
        return Transport.KAYAK;
    }


    /**
     *
     * @param depart
     * @return
     */
    @Override
     public int getVal(Ville depart) {
        if(depart == orig){return 1;}
        return 2;
    }
    /**
     *
     * @param g
     * @param tailleCarte
     */
   @Override
    public void draw(Graphics2D g, int tailleCarte){
        g.setColor(terrain.getColor());
        int l = (int) (tailleCarte * 0.03f);
                int x1, x2, x3, y1, y2, y3;
        float w;
        w = Clickable.width * 0.5f;
        x1 = (int) (x * tailleCarte);
        y1 = (int) (y * tailleCarte);
        
        if (orig != null) {
            x2 = (int) ((orig.x + w) * tailleCarte);
            y2 = (int) ((orig.y + w) * tailleCarte);
        } else {
            x2 = x1 + 20;
            y2 = y1 + 20;
        }
        if (dest != null) {
            x3 = (int) ((dest.x + w) * tailleCarte);
            y3 = (int) ((dest.y + w) * tailleCarte);

        } else {
            x3 = x1 - 20;
            y3 = y1 - 20;

        }
        g.setColor(Color.black);
        util.drawChemin(g, x1, y1, x2, y2, l+2);
        util.drawChemin(g, x1, y1, x3, y3, l+2);
        g.setColor(terrain.getColor());
        util.drawChemin(g, x1, y1, x2, y2, l);
        util.drawChemin(g, x1, y1, x3, y3, l);

        //tracé de la fleche (sens du courant de la riviere)
        Polygon pol = new Polygon();
        g.setColor(Color.LIGHT_GRAY);
        float norm, dX, dY;
        dX = y1 - y3;
        dY = x1 - x3;

        norm = (float)(1/Math.sqrt(dX*dX + dY*dY));
        dX = 20*dX*norm;
        dY = 20*dY*norm;

        pol.addPoint(Math.round(x1 - dX),    Math.round(y1 - dY));
        pol.addPoint(Math.round(x1 + dX),    Math.round(y1 - dY));
        pol.addPoint(Math.round(x1 + dX*0.5f),    Math.round(y1 + dY*0.5f));
        pol.addPoint(Math.round(x1 + 2*dX),  Math.round(y1 + dY));
        pol.addPoint(Math.round(x1+dX),      Math.round(y1 + 2*dY));
        pol.addPoint(Math.round(x1 - 0.5f*dX),  Math.round(y1 + 0.5f*dY));
        pol.addPoint(Math.round(x1 - dX),  Math.round(y1 + dY));



        g.fillPolygon(pol);
}
}